package com.star.vrserver.utils;

import org.springframework.util.DigestUtils;

import java.security.MessageDigest;

/**
 * @author star
 * @date 2023-03-10 16:41
 * @Description MD5加密工具类
 */
public class MD5Util {
    public static final String KEY_MD5 = "MD5";

    /***
     * MD5加密（生成唯一的MD5值）
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryMD5(byte[] data) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance(KEY_MD5);
        md5.update(data);
        return md5.digest();
    }

    public static String enCodeMD5(String password){
        return DigestUtils.md5DigestAsHex(password.getBytes());
    }
}
